package com.wuxuan.algorithm_homework.graph;

/**
 * 图邻接矩阵的实现(无向图的)
 *
 * vertex:顶点 复数形式为:Vertices
 */
public class AdjacencyMatrixDemo {
    //顶点数
    private int numVertices;
    //矩阵
    private int[][] matrix;

    public AdjacencyMatrixDemo(int numVertices) {
        this.numVertices = numVertices;
        //初始化矩阵
        matrix = new int[numVertices][numVertices];
    }

    /**
     * 添加边界
     * @param src
     * @param dest
     */
    public void addEdge(int src, int dest) {
        matrix[src][dest] = 1;
        matrix[dest][src] = 1;
    }

    /**
     * 打印矩阵
     */
    public void printMatrix() {
        for (int i = 0; i < numVertices; i++) {
            for (int j = 0; j < numVertices; j++) {
                System.out.print(matrix[i][j] + " ");
            }
            System.out.println();
        }
    }


    public static void main(String[] args) {
        AdjacencyMatrixDemo a = new AdjacencyMatrixDemo(3);
        a.addEdge(0, 1);
        a.addEdge(0, 2);
        a.addEdge(1, 2);
        a.printMatrix();
    }


}
